package x.y.z;

public class Interview_1_8_ZeroMatrix {
    public void setZeroes(int[][] matrix) {
        boolean[] row = new boolean[matrix.length];
        boolean[] column = new boolean[matrix[0].length];
        for (int i = 0; i < matrix.length; i++) {
            for (int j = 0; j < matrix[0].length; j++) {
                if (matrix[i][j] == 0) {
                    row[i] = true;
                    column[j] = true;
                }
            }
        }

        for (int i = 0; i < row.length; i++) {
            if (row[i]) {
                zeroRow(matrix, i);
            }
        }

        for (int j = 0; j < column.length; j++) {
            if (column[j]) {
                zeroColumn(matrix, j);
            }
        }
    }

    private void zeroRow(int[][] matrix, int i) {
        for (int k = 0; k < matrix[0].length; k++) {
            matrix[i][k] = 0;
        }
    }

    private void zeroColumn(int[][] matrix, int j) {
        for (int k = 0; k < matrix.length; k++) {
            matrix[k][j] = 0;
        }
    }
}
